package cn.org.intelli.zffserver.util;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;

import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;


public class ResultSetTransferUtil {
    public static JSONArray resultSetToJson(ResultSet rs) throws SQLException, JSONException, UnsupportedEncodingException {
        /* 23 */
        JSONArray array = new JSONArray();

        /* 25 */
        ResultSetMetaData metaData = rs.getMetaData();
        /* 26 */
        int columnCount = metaData.getColumnCount();

        /* 28 */
        while (rs.next()) {
            /* 29 */
            JSONObject jsonObj = new JSONObject();

            /* 31 */
            for (int i = 1; i <= columnCount; i++) {
                /* 32 */
                String value = null;
                /* 33 */
                String columnName = metaData.getColumnLabel(i);
                /* 34 */
                if (rs.getString(columnName) != null && !rs.getString(columnName).equals("")) {

                    /* 36 */
                    value = rs.getString(columnName);
                } else {
                    /* 38 */
                    value = "";
                }
                /* 40 */
                jsonObj.put(columnName, value);
            }
            /* 42 */
            array.add(jsonObj);
        }
        /* 44 */
        rs.close();
        /* 45 */
        return array;
    }
}


/* Location:              C:\Users\admin\Desktop\xxm\zjg11\ZjgCaculate-v1.0.jar!\BOOT-INF\classes\cn\org\intelli\zffserve\\util\ResultSetTransferUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */